<template>
	<div class="box">
		<u-form size="medium" ref="itemForm" :model="obj" :rules="itemRules" label-width="100px">
			<u-form-item label="维权类型">{{ order.type_text }}</u-form-item>

			<u-form-item label="处理方式">
				<u-radio-group v-model="obj.state" iconPlacement="right" placement="column">
					<block v-if="order.type == 1">
						<u-radio customStyle="margin-bottom:16rpx" :name="6" label="自动退款"></u-radio>
						<u-radio customStyle="margin-bottom:16rpx" v-if="login_type == 'mall'" :name="5" label="手动退款"></u-radio>
						<u-radio customStyle="margin-bottom:16rpx" :name="3" label="驳回申请"></u-radio>
					</block>

					<block v-if="order.type == 2">
						<block v-if="order.state == 1">
							<u-radio customStyle="margin-bottom:16rpx" :name="2" label="同意申请"></u-radio>
							<u-radio customStyle="margin-bottom:16rpx" :name="7" label="同意退款"></u-radio>
							<u-radio customStyle="margin-bottom:16rpx" :name="3" label="驳回申请"></u-radio>
							<u-radio customStyle="margin-bottom:16rpx" v-if="login_type == 'mall'" :name="5" label="手动退款"></u-radio>
						</block>
						<block v-if="order.state == 13 || order.state == 10">
							<u-radio customStyle="margin-bottom:16rpx" :name="7" label="同意退款"></u-radio>
							<u-radio customStyle="margin-bottom:16rpx" v-if="login_type == 'mall'" :name="5" label="手动退款"></u-radio>
							<block v-if="order.state == 10"><u-radio customStyle="margin-bottom:16rpx" :name="3" label="驳回申请"></u-radio></block>
						</block>
						<block v-if="order.state == 12"><u-radio customStyle="margin-bottom:16rpx" :name="3" label="驳回申请"></u-radio></block>
					</block>

					<block v-if="order.type == 3">
						<block v-if="order.state == 1">
							<u-radio customStyle="margin-bottom:16rpx" :name="3" label="驳回申请"></u-radio>
							<u-radio customStyle="margin-bottom:16rpx" :name="2" label="同意申请"></u-radio>
							<u-radio customStyle="margin-bottom:16rpx" :name="4" label="换货(确认发货)"></u-radio>
						</block>
						<block v-if="order.state == 12 || order.state == 14">
							<u-radio customStyle="margin-bottom:16rpx" :name="4" label="换货(确认发货)"></u-radio>
							<u-radio customStyle="margin-bottom:16rpx" :name="3" label="驳回申请"></u-radio>
						</block>

						<block v-if="order.state == 4"><u-radio customStyle="margin-bottom:16rpx" :name="8" label="关闭申请(换货完成)"></u-radio></block>
					</block>
				</u-radio-group>
			</u-form-item>
			<view class="fks" v-if="obj.state == 4 && (order.state == 1 || order.state == 12)">
				<view style="color:#909399;font-size:12px;line-height:24px;">无需客户寄回商品，商家直接发换货商品</view>
			</view>

			<view class="fks" v-if="obj.state == 6">
				<view style="color:#909399;font-size:12px;line-height:24px;">
					微信支付方式：会返回到相应的支付渠道(如零钱或银行卡)
					<br />
					<block v-if="login_type == 'mall'">
						其他支付方式：会返回到微信钱包(需商户平台余额充足)
						<br />
					</block>

					如有余额抵扣：会返回金额到商城用户余额
					<br />
					如有积分抵扣：申请维权的订单抵扣积分不退还
				</view>
			</view>

			<view class="fks" v-if="obj.state == 7">
				<view style="color:#909399;font-size:12px;line-height:24px;">
					请确认您已经收到客户寄出的商品后同意退款.
					<br />
					微信支付方式：会返回到相应的支付渠道(如零钱或银行卡)
					<br />
					<block v-if="login_type == 'mall'">
						其他支付方式：会返回到微信钱包(需商户平台余额充足)
						<br />
					</block>
					如有余额抵扣：会返回金额到商城用户余额
					<br />
					如有积分抵扣：申请维权的订单抵扣积分不退还
				</view>
			</view>

			<view class="fks" v-if="obj.state == 5"><view style="color:#909399;font-size:12px;line-height:24px;">手动退款：订单会完成退款处理，您用其他方式进行退款</view></view>
			<u-form-item label="驳回申请" v-if="obj.state == 3"><u-input v-model="obj.reject_remake" type="textarea" rows="3"></u-input></u-form-item>

			<u-form-item label="退货地址" v-if="obj.state == 2" @click="show = true">
				<u-input placeholder="选择退货地址" readonly v-model="after_address">
					<template slot="suffix">
						<u-icon name="arrow-down"></u-icon>
					</template>
				</u-input>
				<!--  <el-select v-model="obj.after_address_id" filterable placeholder="请选择退货地址">
          <el-option v-for="item in returnList" :key="item.id" :label="item.status == 1 ? item.name + ' (默认)' : item.name" :value="item.id"></el-option>
        </el-select> -->
			</u-form-item>

			<u-form-item label="选择物流" v-if="obj.state == 4" @click="showex = true">
				<!-- <el-select v-model="obj.deliver_company" filterable placeholder="请选择物流">
          <el-option v-for="item in expressList" :key="item.id" :label="item.name" :value="item.name"></el-option>
        </el-select> -->
				<u-input placeholder="选择物流" readonly v-model="after_address">
					<template slot="suffix">
						<u-icon name="arrow-down"></u-icon>
					</template>
				</u-input>
			</u-form-item>

			<u-form-item label="物流单号" v-if="obj.state == 4"><u-input placeholder="请输入物流单号" v-model="obj.deliver_num"></u-input></u-form-item>
		</u-form>
		<view class="u-flex u-flex-items-center footer">
			<u-button size="small" shape="circle" @click="close">取消</u-button>
			<u-button class="u-m-l-60" type="primary" size="small" shape="circle" @click="saveData">确定</u-button>
		</view>
		<u-picker :show="show" :columns="returnList" keyName="name" @confirm="getaddress"></u-picker>
		<u-picker :show="showex" :columns="expressList" keyName="name" @confirm="getexpress"></u-picker>
	</div>
</template>
<script>
// import {getexpress} from '@/api/shop/freight';
// import {getAddressList} from '@/api/shop/return';
// import {addressOrder, editAfter} from '@/api/shop/order';
// import {logintype_byurl} from '@/utils/auth';
export default {
	name: 'afterAccess',
	data() {
		return {
			isLoading: false,
			expressList: [],
			returnList: [],
			obj: {
				id: '',
				reject_remake: '',
				after_address_id: '',
				deliver_company: '',
				deliver_num: '',
				deliver_time: '',
				state: -1
			},
			after_address: '',
			itemRules: {
				consignee: [
					{
						required: true,
						trigger: 'blur',
						message: '请输入收货人'
					}
				],
				iphone: [
					{
						required: true,
						trigger: 'blur',
						message: '请输入收货人'
					}
				],
				districtSelected: [
					{
						type: 'array',
						required: true,
						message: '请选择所在区域'
					}
				],
				address: [
					{
						required: true,
						trigger: 'blur',
						message: '请输入详细地址'
					}
				]
			},
			login_type: 'mall',
			show: false,
			showex: false
		};
	},
	computed: {
		// address(){
		//   return '111';
		// }
	},
	props: {
		order: {
			type: Object,
			default: function() {
				return {};
			}
		}
	},
	created() {
		// this.login_type = logintype_byurl();
		// //console.log(this.order)
		this.getExpressAll();
		this.getReturnAll();
	},
	methods: {
		getexpress(e) {
			this.order.deliver_company = e.value[0].name;
			this.show = false;
		},
		getaddress(e) {
			this.obj.after_address_id = e.value[0].id;
			this.after_address = e.value[0].name;
			this.show = false;
		},
		//获取所有退货地址
		getReturnAll() {
			this.isLoading = true;
			uni.$u.http
				.post('/shop/return/address/list?page=1&size=100', {}, {custom:{id:10}})
				.then(res => {
					this.isLoading = false;
					this.returnList = [res.msg.data];
					this.$refs.itemForm.setRules(this.itemRules);
				})
				.catch(e => {
					this.isLoading = false;
				});
		},
		//获取所有快递
		getExpressAll() {
			this.isLoading = true;
			uni.$u.http.get('/shop/freight/express', {custom:{id:10}}).then(res => {
				this.isLoading = false;
				this.expressList = [res.msg];
			});
		},
		//保存数据(修改发货地址)
		saveData() {
			this.$refs.itemForm.validate().then(res => {
				let o = {...this.obj};
				o.id = this.order.id;
				if (o.state == 4) {
					o.deliver_time = uni.$u.timeFormat(new Date(), 'YYYY-MM-DD HH:mm:ss');
				}

				this.isLoading = true;
				uni.$u.http
					.put('/shop/aftersale/upAfterState', o, {custom:{id:10}})
					.then(res => {
						this.isLoading = false;
						this.$emit('success');
					})
					.catch(e => {
						this.isLoading = false;
					});
			});
		},
		close() {
			this.$emit('close', 'showAccess');
		}
	}
};
</script>

<style lang="scss" scoped>
//灰色框
.fks {
	background: #f4f6f8;
	//width: 500px;
	padding: 20rpx;
	color: #606266;
	margin-top: 22rpx;
}

.box {
	box-sizing: border-box;
}
</style>
